
/**
 * 用户列表返回数据实体
 */
interface MessageListItemResponse {
    /**
     * id
     */
    id:string;
    /**
     * 消息接收人（通知对象）
     */
    notifier:string;
    /**
     * 通知内容
     */
    content:string;
    /**
     * 通知类型
     */
    type: string;
    /**
     * 通知时间
     */
    time: string;
    /**
     * 失效时间
     */
    invalidTime: string;
    /**
     * 是否已读
     */
    isRead:boolean;
}


/**
 *用户服务
 */
interface IMessageService {
    /**
     * 获取消息列表
     * v1.0
     * @param notifier 消息接收人（通知对象）
     * @param isRead 是否已读
     * @param skip 
     * @param count 
     */
    getList(notifier:string,isRead:boolean, skip: number, count: number): ng.IHttpPromise<ListResponse<MessageListItemResponse>>;

    /**
     * 获取未读消息数
     * @param notifier 消息接收人id
     */
    getNoReadSystemNotifyCount(notifier: string): ng.IHttpPromise<BaseResponse>;

    /**
     * 清空系统消息
     */
    deleteByNotifier(notifier: string): ng.IHttpPromise<BaseResponse>;

    /**
     * 删除单条系统消息
     */
    deleteById(id:string): ng.IHttpPromise<BaseResponse>;
}


class messageService implements IMessageService {
    constructor(private http: ng.IHttpService, private route: routeService) {
    }

    getList(notifier:string,isRead:boolean, skip: number, count: number): ng.IHttpPromise<ListResponse<MessageListItemResponse>> {
        return this.http<ListResponse<MessageListItemResponse>>({
            method: "GET",
            url: this.route.getUrl("systemnotify?notifier={{notifier}}&isRead={{isRead}}&skip={{skip}}&count={{count}}", {
                "notifier": notifier,
                "isRead": isRead,
                "skip": skip,
                "count": count
            })
        });
    }

    getNoReadSystemNotifyCount(notifier: string): ng.IHttpPromise<BaseResponse>{
        return this.http<BaseResponse>({
            method: "GET",
            url: this.route.getUrl("systemnotify/SystemNotifyCount?notifier={{notifier}}", {
                notifier: notifier
            })
        });
    }

    deleteByNotifier(notifier: string): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "GET",
            url: this.route.getUrl('systemnotify/DeleteByNotifier?notifier={{notifier}}', {
            "notifier": notifier
            })
        })
    }

    deleteById(id: string): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "DELETE",
            url: this.route.getUrl('systemnotify/DeleteById/{{id}}', {
                id: id
            })
        })
    }
    


}
angular.module("messageService",[]).service("messageService",['$http','routeService',messageService]);